<!-- 课程详情 -->
<template>
  <div>
     <course-content ref="courseContent" v-if="contentShow === 2" @backContentShow="backContentShow"></course-content>
  <div v-if="contentShow === 1">
    <page-header content="课程详情" @back="goback"></page-header>
   
        <div class="intro">
          <el-row :gutter="20">
            <el-col :span="5"  >
              <img  :src="courseIntro.cover_picture" />
            </el-col>
            <el-col :span="18">
              <div>
                <div>
                 <span  class="item1"> {{ courseIntro.course_name}}</span>
                   <el-tag type="danger" v-if="courseIntro.course_status === 0">禁止</el-tag>
                  <el-tag type="primary" v-else>正常</el-tag>
                 
                </div>
                <div class="item2">课程介绍</div>
                <div class="item3">
                 {{ courseIntro.course_intro}}
                </div>
                <el-row>
                  <el-button type="primary" size="small" @click="addAndUpdate()">添加课程章节</el-button>
                </el-row>
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="directory">课程目录</div>
       
        <el-table :data="tableData">
        
          <el-table-column type="selection" width="55" header-align="center" align="center">
          </el-table-column>

          <el-table-column
            header-align="left"
            label="标题"
          >
          <template slot-scope="scope">
            <div>
              课时{{scope.row.order}}：{{scope.row.title}}
            </div>
          </template>
          </el-table-column>

          <el-table-column
            label="状态"
            header-align="center"
            align="center"
          >
          <template  slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" type="danger" size="small">禁止</el-tag>
            <el-tag v-else size="small">正常</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" header-align="center" align="center">
            <template  slot-scope="scope">
              <el-button type="text" size="small" @click="changeContentShow(scope.row.course_chapter_id)">查看</el-button>
              <el-button type="text" size="small" @click="addAndUpdate(scope.row.course_chapter_id)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      <detail-add-and-update ref="addAndUpdate" @refreshDataList="getChapterList()" :courseInfoId="courseInfoId"></detail-add-and-update>
  </div>
  </div>
</template>

<script>
import PageHeader from '../page-header.vue';
import DetailAddAndUpdate from './detail-add-and-update.vue';
import courseContent from './course-content.vue'
export default {
  components:{PageHeader, DetailAddAndUpdate,courseContent},
  props:{
    courseInfoId :String
  },
  data() {
    return {
      tableData: [
      ],
       courseIntro:{
        course_name:'',
        course_intro:'',
        course_status:''
      },
      contentShow:1
    }
  },
  mounted(){
     this.getCourseIntro();
     this.getChapterList();
  },
  methods:{
    //返回课程管理
    goback(){
      this.$emit('changeShowDetail')
    },
     //获得课程介绍
    getCourseIntro(){
        this.$http({
        url:this.$http.adornUrl('/stu/explore/courseIntro'),
        method:'get',
        params:this.$http.adornParams({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
           if(data&&data.code === 0){
             this.courseIntro = data.data
           }else{
             this.$message(data.msg)
           }
      })
    },
       //获得章节列表
    getChapterList(){
      this.$http({
        url:this.$http.adornUrl('/stu/explore/chapter'),
        method:'get',
        params:this.$http.adornParams({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
           if(data&&data.code === 0){
             this.tableData = data.data
           }else{
             this.$message(data.msg)
           }
      })
    },

    //添加或修改
    addAndUpdate(id){
      this.$nextTick(()=>{
        this.$refs.addAndUpdate.init(id)
      })
    },

    //查看或编辑课程章节内容
    changeContentShow(id){
      console.log(id,"测试接口1")
      this.contentShow = 2
      this.$nextTick(()=>{
        this.$refs.courseContent.init(id)
      })
    },
     
    //返回课程详情
    backContentShow(){
       this.contentShow = 1;
       this.getCourseIntro();
       this.getChapterList();
    }
  }
};
</script>

<style  scoped>
.chapter {
  background-color: lightgray;
  display: flex;
  line-height: 35px;
  font-size: 15px;
}
.chapter .item1 {
  flex: 6;
  margin-left: 20px;
}
.chapter .item2 {
  flex: 1;
}
.chapter .item3 {
  flex: 1;
  color: rgb(0, 153, 255);
  cursor: pointer;
}
.directory {
  border: 1px solid rgb(68, 131, 6);
  line-height: 30px;
  text-align: center;
  color: rgb(76, 136, 15);
  font-size: 18px;
  margin: 10px 0px;
}
.intro .item1 {
  font-size: 18px;
  line-height: 35px;
  font-weight: bold;
  margin-right: 20px;
}
.intro .item2 {
  border-left: 4px solid dodgerblue;
  padding-left: 10px;
  font-size: 13px;
  margin-top: 10px;
}
.intro .item3 {
  height: 64px;
  line-height: 16px;
  margin-top: 15px;
  font-size: 13px;
  color: darkgray;
}
.intro img {
  margin-top: 15px;
  height: 140px;
  width: 100%;
}
</style>
